// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class PROCEDURE_REF_I13 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("61 PR1",61)]
  	    [HL7Field(HL7Version.v23, 61, HL7Repeat.False, HL7Required.True,"PR1")]
	    public PR1 PR1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("62 AUTHORIZATION",62)]
  	    [HL7Field(HL7Version.v23, 62, HL7Repeat.False, HL7Required.False,"AUTHORIZATION_REF_I13")]
	    public AUTHORIZATION_REF_I13 AUTHORIZATION {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			PR1 = PopSegmentParseAndCheckRequired<PR1>(availableData, options, "PR1");
			AUTHORIZATION = ProcessGroup<AUTHORIZATION_REF_I13>(availableData, options, "AUTHORIZATION");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isPR1 = availableData.StartsWith("PR1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PR1", options.Version) || isPR1) {
				return isPR1;
			}
			AUTHORIZATION_REF_I13 testAUTHORIZATION_REF_I13 = new AUTHORIZATION_REF_I13();
			bool grpCCAUTHORIZATION_REF_I13 = (testAUTHORIZATION_REF_I13.CanConsume(availableData, options));
			if (IsRequired("AUTHORIZATION", options.Version) || grpCCAUTHORIZATION_REF_I13) {
				return grpCCAUTHORIZATION_REF_I13;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "PROCEDURE";
			}
        }

        static PROCEDURE_REF_I13() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(PROCEDURE_REF_I13));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (PR1 != null) {
			string segmentValue = PR1.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (AUTHORIZATION != null) {
			string segmentValue = AUTHORIZATION.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

